package food.dao;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import food.model.Food;
import food.util.DBHelp;

public class FoodDao {
	
	   public ArrayList getAllFood() {
		   Connection con = DBHelp.getConnection();
		   ArrayList al = new ArrayList();
		 try {
			PreparedStatement ps = con.prepareStatement("select * from food");
			ResultSet rs = ps.executeQuery();
			while(rs.next()) {
				Food fd = new Food();
				fd.setFoodId(rs.getString("foodId"));
				fd.setFoodName(rs.getString("foodName"));
				fd.setFoodUnit(rs.getString("foodUnit"));
				fd.setFoodPrice(rs.getDouble("foodPrice"));
				al.add(fd);
			}
			DBHelp.close(rs, ps, con);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 return al;
	}	
}
